/***************************************************************************
 *   Copyleft 2006-2007 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>			                           *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#include "Vector2D.h"

/**************************************************************
* Constructors                                                *
***************************************************************/
Vector2D::Vector2D(const Vector2D& vectB) {
	mX = vectB.mX;
	mY = vectB.mY;
}

/**************************************************************
* Operators                                                   *
***************************************************************/
Vector2D& Vector2D::operator+=(const Vector2D& vectB) {
	mX += vectB.mX;
	mY += vectB.mY;

	return *this;
}

Vector2D& Vector2D::operator-=(const Vector2D& vectB) {
	mX -= vectB.mX;
	mY -= vectB.mY;

	return *this;
}

Vector2D Vector2D::operator-() const {
	return Vector2D(-mX, -mY);
}

Vector2D& Vector2D::operator*=(const Vector2D& vectB) {
	mX *= vectB.mX;
	mY *= vectB.mY;

	return *this;
}

Vector2D& Vector2D::operator*=(const cFloat fFactor) {
	mX *= fFactor;
	mY *= fFactor;

	return *this;
}

/**************************************************************
* Friend functions                                            *
***************************************************************/
Vector2D operator+(const Vector2D& vectA, const Vector2D& vectB) {
	return Vector2D(vectA.mX + vectB.mX, vectA.mY + vectB.mY);
}

Vector2D operator-(const Vector2D& vectA, const Vector2D& vectB) {
	return Vector2D(vectA.mX - vectB.mX, vectA.mY - vectB.mY);
}

Vector2D operator*(const Vector2D& vectA, const Vector2D& vectB) {
	return Vector2D(vectA.mX * vectB.mX, vectA.mY * vectB.mY);
}

Vector2D operator*(const Vector2D& vectA, const cFloat fFactor) {
	return Vector2D(vectA.mX * fFactor, vectA.mY * fFactor);
}

/**************************************************************
* Math functions                                              *
***************************************************************/
cVoid Vector2D::Set(cFloat x, cFloat y) {
	mX = x;
	mY = y;
}

cFloat Vector2D::Length() const {
	return sqrtf(Sqrt(mX) + Sqrt(mY));
}

cFloat Vector2D::SqrtLength() const {
	return Sqrt(mX) + Sqrt(mY);
}

cFloat Vector2D::DotProduct(const Vector2D& vectB) {
	return mX * vectB.mX + mY * vectB.mY;
}

